import os
import shutil

class Nvm_Str(object):
    def __init__(self):
        pass

    def NvmRdir(self, filepath):
        path = os.getcwd() + '\output\\' + filepath
        ff = os.path.exists(path)
        if ff:
            shutil.rmtree(path)  # 递归地删除最终目录文件

    def NvmMkdir(self, filepath):
        path = os.getcwd() + '\output\\' + filepath
        ff = os.path.exists(path)
        if not ff:
            os.makedirs(path)

    def _NvmStrCheckBaseName(self, name: str):
        index = self._NvmStrFindLast(name, "_")
        if index == -1:
            return name
        if (name[index:].isdigit()):
            return name[0:index - 1]
        return name

    def _NvmStrFindLast(self, data: str, substr: str):
        index = -1
        for i in range(len(data)):
            if data[i: i+len(substr)] == substr:
                index = i
        return index